# 从1累加到5
count = 1
while count <= 5:
    print(f"当前数字: {count}")
    count += 1  # 等价于 count = count + 1
print("循环结束！")


# 用户输入"quit"时退出
user_input = ""
while user_input.lower() != "quit":
    user_input = input('输入消息（输入"quit"退出）: ')
    print(f"你输入了: {user_input}")

    password = "abc123"
    attempts = 3

    while attempts > 0:
        user_guess = input("请输入密码: ")
        if user_guess == password:
            print("密码正确！")
            break  # 直接跳出整个循环
        else:
            attempts -= 1
            print(f"密码错误！剩余尝试次数: {attempts}")

    if attempts == 0:
        print("账户已锁定！")

        import random

        target = random.randint(1, 100)

        while True:  # 无限循环，依赖break退出
            guess = int(input("猜数字(1-100): "))
            if guess == target:
                print("恭喜猜中！")
                break
            elif guess > target:
                print("太大了！")
            else:
                print("太小了！")

                num = 0
                while num < 10:
                    num += 1
                    if num % 2 == 0:
                        continue  # 跳过偶数
                    print(f"奇数: {num}")

                    while True:
                        age = input("请输入年龄(0-120): ")
                        if not age.isdigit():  # 非数字检测
                            print("请输入数字！")
                            continue
                        age = int(age)
                        if 0 <= age <= 120:
                            break  # 有效输入则退出
                        print("年龄无效！")

                    print(f"录入年龄: {age}岁")




total = 0
while True:
    price = input("输入商品价格(输入done结算): ")
    if price.lower() == "done":
        break
    try:
        total += float(price)
    except ValueError:
        print("无效价格！")
        continue  # 跳过当前错误输入
    print(f"当前总计: ￥{total:.2f}")

print(f"最终应付: ￥{total:.2f}")









import random

# 生成1-100的随机数
secret_number = random.randint(1, 100)
max_attempts = 5  # 最多尝试次数
attempts = 0







print("=== 猜数字游戏（1-100）===")
print(f"你有{max_attempts}次机会")

while attempts < max_attempts:
    guess = int(input(f"第{attempts + 1}次猜数: "))

    if guess == secret_number:
        print(f"恭喜！你用了{attempts + 1}次猜中了数字 {secret_number}")
        break
    elif guess < secret_number:
        print("猜小了！")
    else:
        print("猜大了！")

    attempts += 1
    remaining = max_attempts - attempts
    if remaining > 0:
        print(f"剩余机会: {remaining}")
    else:
        print(f"游戏结束！正确答案是: {secret_number}")

# 扩展功能：询问是否再玩一次
play_again = input("\n再玩一次？(y/n): ").lower()
if play_again == 'y':
    exec(open(__file__).read())  # 重启当前脚本（实际开发建议用函数封装）



total = 0
num = 1

while num <= 100:
    if num % 2 != 0:  # 判断是否为奇数
        total += num
    num += 1

print(f"1~100的奇数和: {total}")  # 输出: 2500





total = 0
num = 1

while num <= 100:
    total += num
    num += 2  # 直接跳过偶数

print(f"1~100的奇数和: {total}")  # 输出: 2500






total = 0
current = 1
print("累加过程:")

while current <= 100:
    print(f"+{current}", end=" ")
    total += current
    current += 2
    if current <= 100:
        print("→", end=" ")

print(f"\n最终结果: {total}")